#------------------------------------------------------------------------------
# Open Dynamics Engine and modular Robots
# Dr. Juan Gonzalez-Gomez. January 2009                          
#------------------------------------------------------------------------------
# GPL LICENSE                                                               
#------------------------------------------------------------------------------

CC = g++
CPPFLAGS =  -Iinclude  
            
DRAWSTUFF_FLAGS =  -Wall -fno-rtti -fno-exceptions -Wall -fomit-frame-pointer \
                   -ffast-math -Iinclude -DdNODEBUG -O2             
            
LIB = -lm -lode 
LIB3D = $(LIB) -lX11 -lGL -lGLU


#-- Drawstuff library
LIBDS = libdrawstuff.a
DEP = drawstuff/drawstuff.o drawstuff/x11.o

#-- Example: box1
NAME1 = box1
DEP1 = box1_ex/$(NAME1).o 

#-- Example: box2
NAME2 = box2
DEP2= box2_ex/$(NAME2).o 

#-- Example: box3
NAME3=box3
DEP3=box3_ex/$(NAME3).o box3_ex/body.o 

#-- Example: compound1
NAME4 = compound1
DEP4 = compound1_ex/$(NAME4).o compound1_ex/body.o 

#-- Example: compound2
NAME5 = compound2
DEP5 = compound2_ex/$(NAME5).o compound2_ex/body.o 

#-- Example: servo
NAME6 = servo
DEP6 = servo_ex/$(NAME6).o servo_ex/module.o 

#-- Example: PP
NAME7 = PP
DEP7 = PP_ex/$(NAME7).o PP_ex/robot.o 

#-- Example: snake robot
NAME8 = snake
DEP8 = snake_ex/$(NAME8).o snake_ex/robot.o 

all: $(LIBDS) $(NAME1) $(NAME2) $(NAME3) $(NAME4) $(NAME5) $(NAME6) $(NAME7) \
              $(NAME8)


#------------------------------
#-- Drawstuff.a
#------------------------------
$(LIBDS): $(DEP)
	    ar rc $(LIBDS) $(DEP)
			
drawstuff/drawstuff.o: drawstuff/drawstuff.cpp   
	  $(CC) $(DRAWSTUFF_FLAGS) -o $@ -c  $< 

drawstuff/x11.o: drawstuff/x11.cpp   
	  $(CC) $(DRAWSTUFF_FLAGS) -o $@ -c  $< 
    
clean::
	  rm -f $(LIBDS) $(DEP) *.bak *~

#------------------------
#-- Example: Box1
#------------------------
$(NAME1): $(DEP1) 
	$(CC) -o $(NAME1) $(DEP1) $(LIB)
  
box1_ex/box1.o: box1_ex/parameters.h
  
clean::
	  rm -f $(NAME1) $(DEP1) *.bak *~
	
#------------------------
#-- Example: Box2	
#------------------------
$(NAME2): $(DEP2)
	$(CC) -o $(NAME2) $(DEP2) $(LIB)
  
box2_ex/box2.o: box2_ex/parameters.h

clean::
	  rm -f $(NAME2) $(DEP2) *.bak *~

#------------------------
#-- Example: Box3			
#------------------------
$(NAME3): $(DEP3) $(LIBDS)
	$(CC) -o $(NAME3) $(DEP3) $(LIBDS) $(LIB3D)

$(DEP3): box3_ex/parameters.h box3_ex/body.h

clean::
	  rm -f $(NAME3) $(DEP3) *.bak *~	
    
#------------------------
#-- Example: Compound1
#------------------------
$(NAME4): $(DEP4) $(LIBDS)
	$(CC) -o $(NAME4) $(DEP4) $(LIBDS) $(LIB3D)

$(DEP4): compound1_ex/parameters.h compound1_ex/body.h

clean::
	  rm -f $(NAME4) $(DEP4) *.bak *~		
    
#-----------------------
#-- Example: Compound2
#-----------------------    
$(NAME5): $(DEP5) $(LIBDS)
	    $(CC) -o $@ $(DEP5) $(LIBDS) $(LIB3D)

$(DEP5): compound2_ex/parameters.h compound2_ex/body.h
  
clean::
	  rm -f $(NAME5) $(DEP5) *.bak *~            

#-----------------------
#-- Example: Servo
#-----------------------    
$(NAME6): $(DEP6) $(LIBDS)
	    $(CC) -o $@ $(DEP6) $(LIBDS) $(LIB3D)

$(DEP6): servo_ex/parameters.h servo_ex/module.h
      
clean::
	  rm -f $(NAME6) $(DEP6) *.bak *~         

#-----------------------
#-- Example: PP
#-----------------------    
$(NAME7): $(DEP7) $(LIBDS)
	    $(CC) -o $@ $^ $(LIB3D)

$(DEP7): PP_ex/parameters.h PP_ex/robot.h

clean::
	  rm -f $(NAME7) $(DEP7) *.bak *~        

#-----------------------
#-- Example: Snake Robot
#-----------------------    
$(NAME8): $(DEP8) $(LIBDS)
	    $(CC) -o $@ $^ $(LIB3D)
      
$(DEP8): snake_ex/parameters.h snake_ex/robot.h

clean::
	  rm -f $(NAME8) $(DEP8) *.bak *~    
		
